﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RecommenderSystem.misc;

namespace RecommenderSystem.algorithms
{
    class RandomAlg : MemoryBased
    {

        private Random _randomGenerator;

        public RandomAlg(Dictionary<string,User> users,ICollection<IDataRecord> dataset) : base(users,dataset)
        {
            this._randomGenerator = new Random();
        }

        public override double calculateSimilarity(User user, User otherUser)
        {
            return 0;
        }

        public override double predictRating(string userID, string itemID)
        {
            var userRatingsHistogram = this._users[userID].GetRatingsHistogram();
            int randomInt = this._randomGenerator.Next(userRatingsHistogram.Values.Sum());
            int i = 0;
            foreach (KeyValuePair<double, int> pair in userRatingsHistogram)
            {
                i += pair.Value;
                if (i >= randomInt)
                {
                    return pair.Key;
                }
            }
            return 0; // if this happens - math broke down.
        }

    }
}
